<template>
  <div class="swiper-content">
    <div class="swiperHead">
      <div class="headLeft">近期大作</div>
      <div class="navList">
        <div
          :class="{
            navItem: true,
            itemActive: gameData.currentIndex === index,
            itemBorder: index === 5,
          }"
          v-for="(item, index) in gameData.navList"
          :key="index"
          @click="changeTabItem(index)"
        >
          {{ item }}
        </div>
      </div>
      <div class="more">
        <a href="https://0day.ali213.net/listhtml/top200_1.html" target="_blank"
          >查看更多</a
        >
      </div>
    </div>
    <div class="swiperCardContent" v-loading="gameData.loading">
      <swiper-item
        v-for="(item, index) in gameData.gameCardList"
        :key="index"
        :gameCardItem="item"
      />
    </div>
  </div>
</template>

<script setup>
import { onMounted, reactive } from "vue";
import swiperItem from "./swiperItem.vue";
import { getRecentGame } from "@/service/youxiaData";
const navList = ["PC", "PS4", "PS5", "XSX", "Xone", "Switch"];
const gameData = reactive({
  gameCardList: [],
  navList: ["PC", "PS4", "PS5", "XSX", "Xone", "Switch"],
  currentIndex: 0,
  loading: false,
});

onMounted(() => {
  getCurrentGameList(0);
});

// 获取选中游戏数据列表
const getCurrentGameList = async (index) => {
  gameData.loading = true;
  const res = await getRecentGame(index);
  gameData.gameCardList = res.data;
  gameData.loading = false;
};
// 切换tab项
const changeTabItem = (index) => {
  gameData.currentIndex = index;
  getCurrentGameList(index);
};
</script>

<style scoped lang="less">
.swiper-content {
  width: 100%;

  display: flex;
  flex-direction: column;
  .swiperHead {
    height: 55px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #f5f5f5;
    .headLeft {
      position: relative;
      font-size: 20px;
      color: #404040;
      font-weight: bold;
      z-index: 2;
      &::after {
        content: "";
        display: block;
        position: absolute;
        left: 0;
        bottom: -20px;
        right: 0;
        margin: auto;
        width: 50px;
        height: 8px;
        background-color: #f76341;
        border-radius: 4px;
      }
    }
    .navList {
      display: flex;
      align-items: center;

      .navItem {
        position: relative;
        padding: 0 15px;
        border-right: 2px solid #ccc;
        cursor: pointer;
      }
      .itemActive {
        font-size: 18px;
        font-weight: bold;
        letter-spacing: 1px;
        color: #f76341;
      }
      .itemBorder {
        border: none;
      }
    }
    .more {
      a {
        font-size: 18px;
        color: #404040;
        margin-right: 30px;
        font-weight: bold;
      }
    }
  }
  .swiperCardContent {
    margin-top: 20px;
  }
}
</style>
